/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author whb108
 */
import javax.swing.*;


public class MainPanel extends JPanel {

    
    TimeConverter myTC = new TimeConverter();
    /**
     * Creates new form MainPanel
     */
    
      public MainPanel(JApplet jaInput) {
        initComponents();
        System.out.println("Creating panel on JApplet");
    }
    
    public MainPanel() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jtfHours = new javax.swing.JTextField();
        jtfMinutes = new javax.swing.JTextField();
        jtfSeconds = new javax.swing.JTextField();
        jtfRun = new javax.swing.JButton();
        jtfOutput = new javax.swing.JTextField();

        jLabel1.setText("Hours              Minutes         Seconds");

        jtfHours.setText("jTextField1");
        jtfHours.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtfHoursFocusLost(evt);
            }
        });

        jtfMinutes.setText("jTextField2");
        jtfMinutes.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jtfMinutesFocusGained(evt);
            }
        });

        jtfSeconds.setText("jTextField3");

        jtfRun.setText("jButton1");
        jtfRun.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfRunActionPerformed(evt);
            }
        });

        jtfOutput.setEditable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jtfHours, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jtfMinutes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jtfSeconds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jtfRun))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addComponent(jtfOutput, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(46, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfHours, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfMinutes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfSeconds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(42, 42, 42)
                .addComponent(jtfOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addComponent(jtfRun)
                .addGap(84, 84, 84))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jtfRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfRunActionPerformed
        // TODO add your handling code here:
        
     
        
      /*  myTC.setSeconds(1);
        myTC.setMinutes(2);
        myTC.setHours(3);
        */
        jtfOutput.setText(myTC.getFormattedTime());
    }//GEN-LAST:event_jtfRunActionPerformed

    private void jtfHoursFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfHoursFocusLost
        // TODO add your handling code here:
           myTC.setHours(Integer.parseInt(jtfHours.getText()));
           
    }//GEN-LAST:event_jtfHoursFocusLost

    private void jtfMinutesFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfMinutesFocusGained
        // TODO add your handling code here:
        jtfMinutes.setSelectionStart(0);
        jtfMinutes.setSelectionEnd(jtfMinutes.getWidth());
    }//GEN-LAST:event_jtfMinutesFocusGained

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jtfHours;
    private javax.swing.JTextField jtfMinutes;
    private javax.swing.JTextField jtfOutput;
    private javax.swing.JButton jtfRun;
    private javax.swing.JTextField jtfSeconds;
    // End of variables declaration//GEN-END:variables
}
